<meta charset="UTF-8">
<?php
include_once("../functions/db_manipulate.php");

if (!init()) {
  redirect("?action=login");
}
if (isset($_GET['galid'])) {

  connectDB();
  startTransaction();

  $resultSet = mysql_query("DELETE FROM gallery WHERE userid='" . $_SESSION['id'] . "' AND id='" . $_GET['galid'] . "'") or die(mysql_error());

  $initiatorAction = \controller\ControllerUtil::getEncodedActionFromUrlWithParameters($_SERVER['HTTP_REFERER']);

  if ($resultSet) {
    commitTransaction();
    redirect("?action=msg&header=header.galimg.delete.success&body=body.galimg.delete.success&view=" . $initiatorAction);
  } else {
    rollbackTransaction();
    redirect("?action=msg&header=header.galimg.delete.failed&body=body.galimg.delete.failed&view=" . $initiatorAction);
  }
}
